package com.maxmlr.music.common.bean;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@Data
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@NoArgsConstructor
public class PageBean extends Bean {
    private static final long serialVersionUID = 1L;

    /**
     * 当前页
     */
    private int pageNum;
    /**
     * 显示记录数
     */
    private int pageSize;
    /**
     * 总页数
     */
    private int pageCount;
    /**
     * 总记录数
     */
    private int rowCount;


    public PageBean(Page<?> page) {
        this((int) page.getCurrent(), (int) page.getSize(), (int) page.getTotal());
    }

    /**
     * @param pageNum  当前页
     * @param pageSize 显示记录数
     * @param rowCount 总记录数
     */
    public PageBean(int pageNum, int pageSize, int rowCount) {
        this.pageSize = pageSize;
        this.pageNum = pageNum;
        this.rowCount = rowCount;
        this.pageCount = rowCount % pageSize == 0 ? rowCount / pageSize : rowCount / pageSize + 1;
    }
}
